#include "FramebufferDrawAction.h"
#include <gl/glew.h>

FramebufferDrawAction::FramebufferDrawAction(void) : Resource()
{
}

FramebufferDrawAction::~FramebufferDrawAction(void)
{
	Dispose();
}

void FramebufferDrawAction::Dispose()
{
	Unbind();
	glDeleteFramebuffers(1,&fbo);
}
void FramebufferDrawAction::Bind()
{
	if(IsAllocated() == false)
	{
		glGenFramebuffers(1,&fbo);
		SetAllocated();
	}

	glBindFramebuffer(GL_FRAMEBUFFER,fbo);
}

void FramebufferDrawAction::Unbind()
{
	glBindFramebuffer(GL_FRAMEBUFFER,0);
}

void FramebufferDrawAction::AttachTextureToColorChanel(Texture * texture,unsigned short slot)
{
	glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0 + slot,GL_TEXTURE_2D,texture->GetGLRes(),0);
}
void FramebufferDrawAction::AttachTextureToDepthChanel(Texture * texture)
{
	glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,texture->GetGLRes(),0);
}